package com.virtium.vpc.action.controller;

import java.util.ArrayList;
import java.util.Iterator;

import com.virtium.vpc.dao.DAOFactory;
import com.virtium.vpc.dao.VpcRevisiontypeDAO;
import com.virtium.vpc.hibernate.model.VpcRevisiontype;

public class VpcRevisiontypeManager {
	private static ArrayList<VpcRevisiontype> arrVpcRevisiontype = null;

	public static ArrayList<VpcRevisiontype> getAll() {
		try {
			if (arrVpcRevisiontype != null && arrVpcRevisiontype.size() > 0)
				return arrVpcRevisiontype;
			VpcRevisiontypeDAO VpcRevisiontypeDAO = DAOFactory.getInstance()
					.getVpcRevisiontypeDAO();
			arrVpcRevisiontype = new ArrayList<VpcRevisiontype>();
			arrVpcRevisiontype.addAll(VpcRevisiontypeDAO.findAll());
		} catch (Exception ex) {
		}
		return arrVpcRevisiontype;
	}
	
	public static String getTextByID(int id){
		getAll();
		Iterator<VpcRevisiontype> iterObject = arrVpcRevisiontype.listIterator();
		while(iterObject.hasNext()){
			VpcRevisiontype object = iterObject.next();
			if(object.getId().equals(id))return object.getText();
			
		}
		return "";
	}
	
	public static void AddNew(String text){
		try{
			VpcRevisiontype object = new VpcRevisiontype();
			object.setText(text);
			VpcRevisiontypeDAO ObjectDAO = DAOFactory.getInstance().getVpcRevisiontypeDAO();
			ObjectDAO.save(object);
			arrVpcRevisiontype = null;
		}catch(Exception ex){
			
		}
	}
	
	public static void Delete(int id){
		try{
			
			VpcRevisiontypeDAO ObjectDAO = DAOFactory.getInstance().getVpcRevisiontypeDAO();
			VpcRevisiontype object = ObjectDAO.findById(id);
			ObjectDAO.delete(object);
			arrVpcRevisiontype = null;
		}catch(Exception ex){
			
		}
	}
}
